package com.custom.pullrecycleview

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.widget.AbsListView
import android.widget.ListView

class MainActivity : AppCompatActivity(), AbsListView.OnScrollListener {

    private val list = mutableListOf<String>()
    private var listView: ListView? = null
    private var pullLayout: PullLayout? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initData()
    }

    private fun initData() {
        for (it in 1..10) {
            list.add("测试$it")
        }
        val listAdapter = ListAdapter(this, list)
        listView = findViewById(R.id.listview)
        pullLayout = findViewById(R.id.pulllayout)
        listView?.adapter = listAdapter
        listView?.setOnScrollListener(this)
    }

    override fun onScroll(view: AbsListView?, firstVisibleItem: Int, visibleItemCount: Int, totalItemCount: Int) {
        val childCount = listView?.childCount
        val childAt = listView?.getChildAt(3)
        val firstVisiblePosition = listView?.firstVisiblePosition
        val lastVisiblePosition = listView?.lastVisiblePosition

        Log.e("childCount***", childCount.toString())
//        Log.d("childAt***", childAt.toString())
        Log.e("firstVisiblePosition***", firstVisiblePosition.toString())
        Log.e("lastVisiblePosition***", lastVisiblePosition.toString())

        Log.e("firstVisibleItem***", firstVisibleItem.toString())
        Log.e("visibleItemCount***", visibleItemCount.toString())
        Log.e("totalItemCount***", totalItemCount.toString())
    }

    override fun onScrollStateChanged(view: AbsListView?, scrollState: Int) {

    }

}
